﻿using System;

namespace GioHangViet.Areas.Admin.Models
{
    public static class Pagging
    {
        public static string HtmlPagging(int countRecord, int currentPage, string path)
        {
            var pageSize = Convert.ToDouble(Resources.Constant.PageSize);
            var floatTotalPage = countRecord/pageSize;
            var totalPage = (int)floatTotalPage;
            if (totalPage < floatTotalPage)
            {
                totalPage++;
            }
            var pageHtml = "";
            pageHtml = @"&lt;div class='widget-bottom'&gt;";
                            pageHtml += "&lt;div class='dataTables_paginate paging_full_numbers' id='DataTables_Table_2_paginate'&gt;";
                                pageHtml +="&lt;a class='first paginate_button paginate_button_disabled' tabindex='1' id='DataTables_Table_2_first' href='"+path+"/1'>First</a&gt;"; 
                                pageHtml +="&lt;a class='previous paginate_button paginate_button_disabled' tabindex='2' id='DataTables_Table_2_previous' href='"+path+"/"+ (currentPage -1) +">Previous</a&gt;";
                                pageHtml += "&lt;span&gt;";
                                if ((currentPage - 3 > 0))
                                {
                                    pageHtml += "&lt;a class='paginate_button' tabindex='3' href='"+path+"/"+(currentPage - 3)+"'&gt;"+(currentPage - 3)+"&lt;/a&gt;";
                                }
                                if (currentPage - 2 > 0)
                                {
                                    pageHtml += "&lt;a class='paginate_button' tabindex='4' href='"+path+"/"+(currentPage - 2)+"'&gt;"+(currentPage - 2)+"&lt;/a&gt;";
                                }
                                if (currentPage - 1 > 0)
                                {
                                    pageHtml += "&lt;a class='paginate_button' tabindex='5' href='" + path + "/" + (currentPage - 1) + "'&gt;" + (currentPage - 1) + "&lt;/a&gt;";
                                }
                                pageHtml += "&lt;a class='paginate_active' tabindex='6' href='" + path + "/" + (currentPage) + "'&gt;" + currentPage + "&lt;/a&gt;";
                                if ((currentPage + 1 < totalPage))
                                {
                                    pageHtml += "&lt;a class='paginate_button' tabindex='7' href='" + path + "/" + (currentPage + 1) + "'&gt;" + (currentPage + 1) + "&lt;/a&gt;";
                                }
                                if (currentPage + 2 < totalPage)
                                {
                                    pageHtml += "&lt;a class='paginate_button' tabindex='8' href='" + path + "/" + (currentPage + 2) + "'&gt;" + (currentPage + 2) + "&lt;/a&gt;";
                                }
                                if (currentPage + 3 < totalPage)
                                {
                                    pageHtml += "&lt;a class='paginate_button' tabindex='9' href='" + path + "/" + (currentPage + 3) + "'&gt;" + (currentPage + 3) + "&lt;/a&gt;";
                                }
                                pageHtml += "&lt;/span&gt;";
                                pageHtml += "&lt;a class='next paginate_button' tabindex='10' id='DataTables_Table_2_next' href='" + path + "/" + (currentPage + 1) + "'>Next</a&gt;";
                                pageHtml += "&lt;a class='last paginate_button' tabindex='11' id='DataTables_Table_2_last' href='" + path + "/" + (totalPage) + "'>Last</a&gt;";
                            pageHtml += "&lt;/div&gt;";
                            pageHtml += "&lt;div class='clear'&gt;";
                            pageHtml += "&lt;/div&gt;";
            pageHtml += "&lt;/div&gt;";
            return pageHtml;
        }
    }
}